package com.google.common.collect;

import com.google.common.base.Preconditions;

import java.util.Collection;
import java.util.Map;


public class Multimaps {
    public static <K, V, M extends Multimap<K, V>> M invertFrom(
            Multimap<? extends V, ? extends K> source, M dest) {
        Preconditions.checkNotNull(dest);
        for (Map.Entry<? extends V, ? extends Collection<? extends K>> entry : source.entries()) {
            for(K k : entry.getValue()){
                dest.put(k, entry.getKey());
            }
        }
        return dest;
    }
}
